package com.general.template.controller;

import com.general.template.enums.ResultEnum;
import com.general.template.pojo.PowerDimension;
import com.general.template.pojo.PowerMeasurementScale;
import com.general.template.service.PowerMeasurementScaleService;
import com.general.template.utils.Pages;
import com.general.template.utils.Result;
import com.general.template.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author: 杰哥
 * Date: 2021/2/16 20:20
 * @Description:
 **/
@RequestMapping("measurementScale")
@RestController
@Api(value="不同岗位维度管理",description = "对不同岗位维度管理的查看和修改")
public class MeasurementScaleController {

    @Autowired
    private PowerMeasurementScaleService measurementScaleService;

    /**
     * 添加考卷
     *
     * @author 杰哥
     * @date 2021/2/16 20:31
     * @param scale
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="add",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value="添加考卷",notes = "添加考卷")
    public Result<Object> add(@RequestBody PowerMeasurementScale scale){
        scale.setCreateTime(new Date());
        boolean save = this.measurementScaleService.save(scale);
        if (save){
            return new Result<>(ResultEnum.SUCCESS,"添加成功!");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"添加失败!");
        }
    }

    /**
     * 修改考卷
     *
     * @author 杰哥
     * @date 2021/2/16 20:32
     * @param scale
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="update",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value="修改考卷",notes = "修改考卷")
    public Result<Object> update(@RequestBody PowerMeasurementScale scale){
        boolean save = this.measurementScaleService.updateById(scale);
        if (save){
            return new Result<>(ResultEnum.SUCCESS,"修改成功!");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"修改失败!");
        }
    }

    /**
     * 禁用考卷
     *
     * @author 杰哥
     * @date 2021/2/16 20:34
     * @param id
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="delete/{id}",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value="禁用考卷",notes = "禁用考卷")
    public Result<Object> delete(@PathVariable("id") Integer id){
        PowerMeasurementScale scale = new PowerMeasurementScale();
        scale.setId(id);
        scale.setStatus(1);
        boolean b = this.measurementScaleService.updateById(scale);
        if (b){
            return new Result<>(ResultEnum.SUCCESS,"禁用成功!");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"禁用失败!");
        }
    }

    /**
     * 启用考卷
     *
     * @author 杰哥
     * @date 2021/2/16 20:34
     * @param id
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="enable/{id}",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value="启用考卷",notes = "启用考卷")
    public Result<Object> enable(@PathVariable("id") Integer id){
        PowerMeasurementScale scale = new PowerMeasurementScale();
        scale.setId(id);
        scale.setStatus(0);
        boolean b = this.measurementScaleService.updateById(scale);
        if (b){
            return new Result<>(ResultEnum.SUCCESS,"启用成功!");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"启用失败!");
        }
    }

    /**
     * 后台管理分页查询
     *
     * @author 杰哥
     * @date 2021/2/16 21:11
     * @param pages
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="pageList",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value="后台管理分页查询",notes = "后台管理分页查询")
    public Result<Object> pageList(@RequestBody Pages<PowerMeasurementScale> pages){
        Pages list = this.measurementScaleService.pageList(pages);
        return new Result<>(ResultEnum.SUCCESS,list);
    }

    /**
     * 前台考卷查询
     *
     * @author 杰哥
     * @date 2021/2/16 21:24
     * @param jobId
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="getList/{jobId}",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value="前台考卷查询",notes = "前台考卷查询")
    public Result<Object> getList(@PathVariable("jobId") Integer jobId){
        if (StringUtils.isNullOrEmpty(jobId)){
            return new Result<>(ResultEnum.PARAMS_NULL);
        }
        List<PowerMeasurementScale> list = this.measurementScaleService.getList(jobId);
        return new Result<>(ResultEnum.SUCCESS,list);
    }

}
